package com.itheima.clientAndService02;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServicerClass {
    public static void main(String[] args) throws IOException {
        //创建服务器ServerSocket对象，指定端口
        ServerSocket ss = new ServerSocket(10012);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,
                5,
                20,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        while (true) {
            //将ServerSocket对象转换成Socket对象，Socket对象可以创建用于网络传输的字节输入或输出流
            Socket accept = ss.accept();
            RunnableClass rc = new RunnableClass(accept);
            pool.submit(rc);
        }
//        ss.close();
    }
}
